#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Option.h>
#pragma unmanaged 
#include <ql\instruments\swaption.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#define STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ISwaption
	public ref class CSwaption : 
            public COption,
            public Cephei::QL::Instruments::ISwaption
	{
	protected: 
		boost::shared_ptr<QuantLib::Swaption>* _ppSwaption;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::Swaption>* _phSwaption;
#endif
		Object^ _SwaptionOwner;     // reference to object that manages the storage for this object
	internal:
		CSwaption (Cephei::QL::Instruments::IVanillaSwap^ swap, Cephei::QL::IExercise^ exercise, Microsoft::FSharp::Core::FSharpOption<QL::Instruments::Settlement::TypeEnum>^ delivery, Cephei::QL::IPricingEngine^ QL_Pricer);
        CSwaption (boost::shared_ptr<QuantLib::Swaption>& childNative, Object^ owner);
        CSwaption (QuantLib::Swaption& childNative, Object^ owner);
        CSwaption (CSwaption^ copy);
        CSwaption (System::Type^ t);
#ifdef STRUCT
        CSwaption (QuantLib::Swaption childNative);
#endif       
#ifdef HANDLE
		CSwaption (QuantLib::Handle<QuantLib::Swaption>& childNative, Object^ owner);
		CSwaption (QuantLib::Handle<QuantLib::Swaption> childNative);
#endif
		virtual ~CSwaption ();
		!CSwaption ();

	internal:
		QuantLib::Swaption& GetReference ();
		boost::shared_ptr<QuantLib::Swaption>& GetShared ();
		QuantLib::Swaption* GetPointer ();
        void SetSwaption (boost::shared_ptr<QuantLib::Swaption> native)
        {
            if (_ppSwaption != NULL)
                delete _ppSwaption;
            _ppSwaption = new boost::shared_ptr<QuantLib::Swaption> (native);
            SetOption (boost::dynamic_pointer_cast<QuantLib::Option> (*_ppSwaption));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::Swaption>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
		virtual Double ImpliedVolatility (Double price, Cephei::QL::Termstructures::IYieldTermStructure^ discountCurve, Double guess, Microsoft::FSharp::Core::FSharpOption<Double>^ accuracy, Microsoft::FSharp::Core::FSharpOption<UInt32>^ maxEvaluations, Microsoft::FSharp::Core::FSharpOption<Double>^ minVol, Microsoft::FSharp::Core::FSharpOption<Double>^ maxVol) ;
        property Boolean IsExpired 
        {
		    virtual Boolean get () ;
        }
        property QL::Instruments::Settlement::TypeEnum SettlementType 
        {
		    virtual QL::Instruments::Settlement::TypeEnum get () ;
        }
        property QL::Instruments::VanillaSwap::TypeEnum Type 
        {
		    virtual QL::Instruments::VanillaSwap::TypeEnum get () ;
        }
        property Cephei::QL::Instruments::IVanillaSwap^ UnderlyingSwap 
        {
		    virtual Cephei::QL::Instruments::IVanillaSwap^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CSwaption_Factory : public System::MarshalByRefObject,  public ISwaption_Factory
	{
	public:
        virtual ISwaption^ Create (Cephei::QL::Instruments::IVanillaSwap^ swap, Cephei::QL::IExercise^ exercise, Microsoft::FSharp::Core::FSharpOption<QL::Instruments::Settlement::TypeEnum>^ delivery, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
